#include<bits/stdc++.h>
using namespace std;
int T,n,m,l,limit,x,ans;
int d[100005],v[100005],a[100005];
int b[1000005],sum[1000005];
void solve(){
    ans=0;
    scanf("%d%d%d%d",&n,&m,&l,&limit);
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",&d[i],&v[i],&a[i]);
    }
    for(int i=1;i<=m;i++){
        scanf("%d",&x);
        b[x]++;
    }
    for(int i=1;i<=l;i++){
        sum[i]=sum[i-1]+a[i];
    }
    for(int i=1;i<=n;i++){
        if(d[i]<=limit&&a[i]<0)continue;
        if(a[i]<0){
            double k=1.0*(limit-v[i])/a[i]+d[i];
            int tmp=int(k);
            if(sum[tmp]!=sum[d[i]-1])ans++;
        }
        else if(a[i]>0){
            double k=1.0*(limit-v[i])/a[i]+d[i];
            int tmp=ceil(k);
            if(sum[tmp]!=sum[l])ans++;
        }
        else if(d[i]>limit)ans++;
    }
    printf("%d 0\n",ans);
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&T);
    for(int i=1;i<=T;i++)solve();
    return 0;
}
